home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 490 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.7 KB  |  51 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: "Paul D. DeRocco" <pderocco@ix.netcom.com>
  3. Newsgroups: comp.std.c++
  4. Subject: Returning void
  5. Date: 18 Feb 1996 02:14:49 GMT
  6. Organization: ?
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <3125C4A3.5C00@ix.netcom.com>
  9. NNTP-Posting-Host: taumet.eng.sun.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (Win95; I)
  14. Content-Length: 957
  15. Originator: clamage@taumet
  16.  
  17. The C++ standard doesn't allow a return statement with an expression to 
  18. be used in a function whose return type is void.
  19.  
  20. I suggest that it should be legal to return a void expression from a 
  21. function whose type is void. Why? It can be useful in templates. 
  22. Consider the following:
  23.  
  24.     template <class T, class R> class Functor {
  25.     public:
  26.         R& operator()() { return (obj.*mem)(); }
  27.         Functor(T& o, R& (T::*m)()): obj(o), mem(m) {}
  28.     private:
  29.         T& obj;
  30.         R& (T::*mem)();
  31.     }
  32.  
  33. This defines a functor containing a pointer to an object to be operated 
  34. on, and a pointer to a member function defined for that object. It 
  35. should work for any member function that takes no arguments and returns 
  36. a result. Unfortunately, it won't work for a member function that 
  37. returns void. If return were modified as described above, this function 
  38. template would work for member functions that return void as well.
  39.  
  40. -- 
  41.  
  42. Ciao,
  43. Paul D. DeRocco
  44.  
  45. [ To submit articles: Try just posting with your newsreader.  If that fails,
  46.               use mailto:std-c++@ncar.ucar.edu
  47.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  48.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  49.   Comments? mailto:std-c++-request@ncar.ucar.edu
  50. ]
  51.